package com.taoyeshu.common.utils;

import org.apache.shiro.SecurityUtils;

import com.taoyeshu.modules.sys.entity.User;

public class UserContext {

	public static final String USER_IN_SESSION = "user_in_session";
	public static final String USER_IN_SESSION_ID = "user_in_session_id";

	public static User get() {
		return (User) SecurityUtils.getSubject().getSession().getAttribute(USER_IN_SESSION);
	}

	public static Integer getId() {
		return (Integer) SecurityUtils.getSubject().getSession().getAttribute(USER_IN_SESSION_ID);
	}

	public static void set(User user) {
		if (user != null) {
			SecurityUtils.getSubject().getSession().setAttribute(USER_IN_SESSION, user);
		}
	}

	public static void putId(Integer id) {
		SecurityUtils.getSubject().getSession().setAttribute(USER_IN_SESSION_ID, id);
	}

	public static void remove() {
		SecurityUtils.getSubject().getSession().removeAttribute(USER_IN_SESSION);
	}
}
